package cn.tedu.restaurant.controller;


import cn.tedu.restaurant.common.JsonResult;
import cn.tedu.restaurant.entity.Comment;
import cn.tedu.restaurant.entity.Dishes;
import cn.tedu.restaurant.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author JachinLin
 * @since 2020-10-07
 */
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    @Resource
    private CommentService commentService;

    public static final Integer SUCCESS = 200;

    @RequestMapping("/reg")
    public JsonResult<Void> reg(@RequestParam("nickName") String nickName,@RequestParam("content") String content,@RequestParam("id") Integer id,HttpSession session) {
        JsonResult<Void> result = new JsonResult<Void>(SUCCESS);
        String username = session.getAttribute("username").toString();
        commentService.insertComment(nickName,content,id,username);
        return result;
    }


    @RequestMapping("list")
    public JsonResult<List<Comment>> listComment(@RequestParam("id") Integer id) {
        JsonResult<List<Comment>> result = new JsonResult<List<Comment>>(SUCCESS);
        result.setData(commentService.listComment(id));
        return result;
    }

}
